<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加spu</title>
    <script src="../static/vue.min.js"></script>
    <script src="../elements/element.js"></script>
    <link rel="stylesheet" href="../elements/element.css">
    <script src="../static/jquery-1.8.0.js"></script>
</head>

<style scoped>
    .main {
        display: inline;
    }

    .button-new-tag {
        color: #70bdff;
        margin-left: 15px;
        height: 25px;
        padding-top: 0;
        padding-bottom: 0;
    }

    .input-new-tag {
        width: 90px;
        margin-left: 15px;
    }

    .check-group {
        display: inline;
    }

</style>


<body>

<div id="app">
    <el-row>
        <el-col :span="24"><div class="grid-content bg-purple-dark"></div>
            <el-steps :active="active" finish-status="success">
                <el-step title="基本信息">
                </el-step>
                <el-step title="规格参数">
                </el-step>
                <el-step title="销售属性" >
                </el-step>
                <el-step title="SKU信息" >
                </el-step>
            </el-steps>
        </el-col>
        <el-col :span="24">
            <div v-show="active==0" name="1">我是基本信息
                <el-card class="box-card" style="width:80%;margin:20px auto">
                    <!-- ref验证规则是否通过  rules设置验证规则-->
                    <el-form ref="spuBaseInfoRules" :model="spuform" label-width="80px" :rules="spuBaseInfoRules">
                        <el-form-item label="商品名称" prop="spu_name">
                            <el-input v-model="spuform.spu_name"></el-input>
                        </el-form-item>
                        <el-form-item label="商品描述" prop="spu_description">
                            <el-input v-model="spuform.spu_description"></el-input>
                        </el-form-item>
                        <el-form-item label="选择分类" prop="catalog_id">
                            <el-cascader expand-trigger="hover" v-model="spuform.catalog_id" :options="javaapi.catelogTreeList" :props="catelogTreeProps" @change="chancatelogByBrand" ></el-cascader>
                        </el-form-item>
                        <el-form-item label="选择品牌" prop="brand_id">
                            <el-select v-model="spuform.brand_id" placeholder="请选择品牌">
                                <el-option  :label="brand.name"  :key="brand.brand_id"  :value="brand.brand_id" v-for=" brand in javaapi.selectBrand">{{brand.name}}</el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="商品重量">
                            <el-input-number v-model.number="spuform.weight" :min="0" :max="1000" lebel="kg" :step="0.1"></el-input-number>
                        </el-form-item>
                        <el-form-item label="设置积分">
                            <el-col :span="2"><label>金币</label></el-col>
                            <el-col :span="10"><el-input-number v-model.number="spuform.bounds.buyBounds" :min="0" :max="10000" :step="1"></el-input-number></el-col>
                            <el-col :span="2"><label>成长值</label></el-col>
                            <el-col :span="10"><el-input-number v-model.number="spuform.bounds.growBounds" :min="0" :max="10000" :step="1"></el-input-number></el-col>
                        </el-form-item>
                        <el-form-item label="商品介绍" prop="decript">
                            <el-upload
                                    :action="uploadUrl"
                                    list-type="picture-card"
                                    :on-success="uploadSuccess"
                                    :on-preview="handlePictureCardPreview"
                                    :on-remove="handleRemove" with-credentials="true">
                                <i class="el-icon-plus"></i>
                            </el-upload>
                        </el-form-item>
                        <!-- 图片预览 -->
                        <el-dialog :visible.sync="dialogVisible">
                            <img width="100%" :src="dialogImageUrl" alt="">
                        </el-dialog>
                        <!-- spuBaseInfoRules：对应的vue里定义的验证对象 -->
                        <el-button type="success"  @click="submitFormOne('spuBaseInfoRules')">下一步规格参数</el-button>
                    </el-form>
                </el-card>

            </div>
        </el-col>


        <el-col :span="24"><div class="grid-content bg-purple-dark"> &nbsp;</div>
            <div v-show="active==1" name="2">我是规格参数
                <el-card class="box-card" style="width:80%;margin:20px auto">

                    <el-tabs :tab-position="'left'">
                        <el-tab-pane :label="group.attr_group_name" v-for=" (group,left) in javaapi.tabGroupValue">
                            <el-form   :label-position="'top'"  v-model="spuform" label-width="80px">
                                <el-form-item v-for="(groupAttrs,right) in group.allAttrByGroupIdAndCatelogId" :label="groupAttrs.attr_name">
                                    <el-input v-model="javaapi.tabGroupValue[left].allAttrByGroupIdAndCatelogId[right].attr_id" v-show="false"  :value="groupAttrs.attr_id"></el-input>
                                    <el-input v-model="javaapi.tabGroupValue[left].allAttrByGroupIdAndCatelogId[right].attr_name" v-show="false"  :value="groupAttrs.attr_name"></el-input>
                                    <el-input v-model="javaapi.tabGroupValue[left].allAttrByGroupIdAndCatelogId[right].attrValues"></el-input>
                                </el-form-item>
                            </el-form>
                        </el-tab-pane>
                    </el-tabs>

                    <div style="margin:auto">
                        <el-button style="margin-top: 12px;" @click="active=0">上一步</el-button>
                        <el-button style="margin-top: 12px;" @click="submitFormTwo('skusaleAttr')">下一步销售属性</el-button>
                    </div>


                </el-card>
            </div>
        </el-col>


        <el-col :span="24"><div class="grid-content bg-purple-dark"> &nbsp;</div>
            <div v-show="active==2" name="3">我是销售属性
                <el-card class="box-card" style="width:80%;margin:20px auto">
                    <el-form ref="spuform" :model="spuform" label-width="80px">

                        <el-form-item v-model="javaapi.attrs_Sales" v-for="(attr,ids) in javaapi.attrs_Sales" :label="attr.attr_name+':'" >

                            <el-checkbox v-model="saleattrbyvalues.checked"  v-if="attr.attr_values!=null"  v-for="saleattrbyvalues in attr.attr_values" :label="saleattrbyvalues.values">{{saleattrbyvalues.values}}</el-checkbox>
                            <el-button class="button-new-tag" v-show="!javaapi.attrs_Sales[ids].view"  size="small" @click="showInput(ids)">
                                <i class="el-icon-plus"></i>自定义</el-button>
                            <el-input
                                    class="input-new-tag"
                                    v-show="javaapi.attrs_Sales[ids].view"
                                    v-model="javaapi.attrs_Sales[ids].value"
                                    @keyup.enter.native="handleInputConfirm(ids)"
                                    @blur="handleInputConfirm(ids)"
                                    size="small"
                            ></el-input>
                        </el-form-item>

                        <el-button style="margin-top: 12px;" @click="active=1">上一步</el-button>
                        <el-button style="margin-top: 12px;" @click="skuData">设置sku信息</el-button>
                    </el-form>
                </el-card>
            </div>
        </el-col>


        <el-col :span="24">
            <div v-show="active==3" name="3">我是SKU信息
                <el-card class="box-card" style="width:80%;margin:20px auto">

                    <el-table :data="spuform.skus">
                        <el-table-column label="属性组合">
                         <el-table-column  v-for="(item,index) in attrs_Sales_Attrs" :label="item.attr_name" :key="item.attr_id">
                             <template slot-scope="scope">
                                 <span style="margin-left: 10px">{{scope.row.attr[index].attr_value}}</span>
                             </template>
                        </el-table-column>
                        </el-table-column>
                        <el-table-column label="商品名称" prop="sku_name">
                            <!-- scope.row就是表格里的数据，类似于我们打点调用data.*** -->
                            <template slot-scope="scope">
                                <el-input v-model="scope.row.sku_name"></el-input>
                            </template>
                        </el-table-column>
                        <el-table-column label="标题" prop="sku_title">
                            <template slot-scope="scope">
                                <el-input v-model="scope.row.sku_title"></el-input>
                            </template>
                        </el-table-column>
                        <el-table-column label="副标题" prop="sku_subtitle">
                            <template slot-scope="scope">
                                <el-input v-model="scope.row.sku_subtitle"></el-input>
                            </template>
                        </el-table-column>
                        <el-table-column label="价格" prop="price">
                            <template slot-scope="scope">
                                <el-input v-model="scope.row.price"></el-input>
                            </template>
                        </el-table-column>
                        <!-- 隐藏的table expand：则显示为一个可展开的按钮 -->
                        <el-table-column type="expand">
                            <template slot-scope="scope">
                                <el-row>
                                    <el-col :span="24">
                                        <label style="display:block;float:left">添加图集</label>
                                        <el-upload
                                                :action="uploadUrl"
                                                list-type="picture-card"
                                                :on-success="function (res,file){ return uploadBySkuImgSuccess(res,file,scope.$index)}"
                                                :on-preview="handlePictureCardPreview"
                                                :on-remove="function (file, fileList,index){return handleRemoveBysku(file, fileList,scope.$index)}" with-credentials="true">
                                            <i class="el-icon-plus"></i>
                                        </el-upload>

                                    </el-col>
                                </el-row>
                                <!-- 折扣，满减，会员价 -->
                                <el-form :model="scope.row">
                                    <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="设置折扣">
                                                <label>满</label>
                                                <el-input-number
                                                        style="width:160px"
                                                        :min="0"
                                                        controls-position="right"
                                                        v-model="scope.row.fullCount"
                                                ></el-input-number>
                                                <label>件</label>

                                                <label style="margin-left:15px;">打</label>
                                                <el-input-number
                                                        style="width:160px"
                                                        v-model="scope.row.discount"
                                                        :precision="2"
                                                        :max="1"
                                                        :min="0"
                                                        :step="0.01"
                                                        controls-position="right"
                                                ></el-input-number>
                                                <label>折</label>
                                                <el-checkbox
                                                        v-model="scope.row.countStatus"
                                                        :true-label="1"
                                                        :false-label="0"
                                                >可叠加优惠</el-checkbox>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="24">
                                            <el-form-item label="设置满减">
                                                <label>满</label>
                                                <el-input-number
                                                        style="width:160px"
                                                        v-model="scope.row.fullPrice"
                                                        :step="100"
                                                        :min="0"
                                                        controls-position="right"
                                                ></el-input-number>
                                                <label>元</label>
                                                <label style="margin-left:15px;">减</label>
                                                <el-input-number
                                                        style="width:160px"
                                                        v-model="scope.row.reducePrice"
                                                        :step="10"
                                                        :min="0"
                                                        controls-position="right"
                                                ></el-input-number>
                                                <label>元</label>
                                                <el-checkbox
                                                        v-model="scope.row.priceStatus"
                                                        :true-label="1"
                                                        :false-label="0"
                                                >可叠加优惠</el-checkbox>
                                            </el-form-item>
                                        </el-col>

                                        <el-col :span="24">
                                            <el-form-item label="设置会员价" v-if="scope.row.memberPrice.length>0">
                                                <br />
                                                <!--   @change="handlePriceChange(scope,mpidx,$event)" -->
                                                <el-form-item v-for="(mp,mpidx) in scope.row.memberPrice" :key="mp.id">
                                                    {{mp.name}}
                                                    <el-input v-show="false" v-model="scope.row.memberPrice[mpidx].id"></el-input>
                                                    <el-input-number
                                                            style="width:160px"
                                                            v-model="scope.row.memberPrice[mpidx].price"
                                                            :precision="2"
                                                            :min="0"
                                                            controls-position="right"
                                                    ></el-input-number>
                                                </el-form-item>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </template>
                        </el-table-column>
                    </el-table>

                    <el-form ref="spuform" :model="spuform" label-width="80px">

                        <el-button style="margin-top: 12px;" @click="active=2">上一步</el-button>
                        <el-button style="margin-top: 12px;" @click="endaddspuform('skuxinxi')">下一步</el-button>
                    </el-form>
                </el-card>
            </div>
        </el-col>

    </el-row>
</div>
</body>
<script src="../static/axios.min.js"></script>

<script src="../static/global.js"></script>
<script>
    let app=new Vue({
        el:'#app',
        data : {
            dialogImageUrl: '',//控制预览图片的展示的地址
            dialogVisible: false,//控制是否一直展示
            uploadUrl:glodate.serverZuul+"brand/filesUpload",//上传图片时发送的地址
            javaapi:{
                //tree的集合
                catelogTreeList:[],
                //分类下的品牌的数组
                selectBrand:[],
                tabGroupValue:[],//当前分类下的全部分组信息
                attrs_Sales:[],//后台传来的全部销售属性和值
                memberLevels:[]//后台传来的全部会员等级
            },
            //进度条
            active: 0,
            form:{},
            attrs_Sales_Attrs:[],//选中的销售属性名


            spuform: {
                spu_name: '',//spu的名字
                spu_description:'',//spu描述
                catalog_id:'',//分类id(分类级联选择器上的id)
                weight: '',//重量
                brand_id: '',//品牌id

                delivery: false,
                bounds: {
                    //积分
                    buyBounds: 0,
                    growBounds:0
                },
                baseAttrs:[],//attr往product-attr-value表里搞数据的
                skus:[],//存储sku信息
                images: [],//图片
                decript: []//spu描述表里的商品介绍
            },
            //验证 对应的prop属性
            spuBaseInfoRules: {
                spu_name: [
                    { required: true, message: "请输入商品名字", trigger: "blur" }
                ],
                spu_description: [
                    { required: true, message: "请编写一个简单描述", trigger: "blur" }
                ],
                catalog_id: [
                    { required: true, message: "请选择一个分类", trigger: "blur" }
                ],
                brand_id: [
                    { required: true, message: "请选择一个品牌", trigger: "blur" }
                ],
                decript: [
                    { required: true, message: "请上传商品详情图集", trigger: "blur" }
                ],
                images: [
                    { required: true, message: "请上传商品图片集", trigger: "blur" }
                ],
                weight: [
                    {
                        type: "number",
                        required: true,
                        message: "请填写正确的重量值",
                        trigger: "blur"
                    }
                ]
            },

            //转换tree的
            catelogTreeProps: {
                label: 'title',
                value: 'id',
                children: 'children'
            },
        },
        created () {
            this.getTree(),
               this.getMemberLevel()

        },
        methods: {
            //查找全部分类
            getTree(){
                axios.get(glodate.serverZuul+"category/getTree").then(response=>{
                    this.javaapi.catelogTreeList=response.data.data;
                 //   console.log(response.data.data);

                })
            },
            //查找第三个分类
            //当分类发生变化时查找分类下的品牌
            chancatelogByBrand(){
                //只要第三层的分类id
                this.spuform.catalog_id=this.spuform.catalog_id[2];//当前三级分类的id
                axios.get(glodate.serverZuul+"brand/findAllBrandByCatalogId/"+this.spuform.catalog_id).then(response=>{
                    this.javaapi.selectBrand=response.data.data;
               //     console.log(this.spuform.catalog_id)
                })
            },
            //图片展示
            //删除图片信息
            handleRemove(file, fileList) {
            //    console.log(file, fileList);
                const filePath = file.response
                console.log("dizhi:"+JSON.stringify(filePath));
                $.ajax({
                    type:'delete',
                    url:glodate.serverZuul+"brand/deletefiles",
                    data:{'objectName':filePath}
                })
// this.spuform.decript.push(JSON.stringify(filePath.data))
                // 从pics数组中，找到图片的索引值
                const i = this.spuform.decript.findIndex(x => x === filePath)
                // 调用数组中的splice方法，移除图片信息
                this.spuform.decript.splice(i, 1);
                console.log("删除后的"+JSON.stringify(this.spuform.decript))

            },
            handleRemoveBysku(file, fileList,index) {

                //    console.log(file, fileList);
                const filePath = file.response
                $.ajax({
                    type:'delete',
                    url:glodate.serverZuul+"brand/deletefiles",
                    data:{'objectName':filePath}
                })
                // 从pics数组中，找到图片的索引值
                const i = this.spuform.skus[index].images.findIndex(x => x === filePath)
                // 调用数组中的splice方法，移除图片信息
               this.spuform.skus[index].images.splice(i, 1);
                console.log("删除后的"+ this.spuform.skus[index].images)

            },
            //默认图片
            checkDefaultImg(row, index, img) {
                console.log("默认图片", row, index);
                //这个图片被选中了，
                row.images[index].imgUrl = img; //默认选中
                row.images[index].defaultImg = 1; //修改标志位;
                //修改其他人的标志位
                row.images.forEach((item, idx) => {
                    if (idx != index) {
                        row.images[idx].defaultImg = 0;
                    }
                });
            },
            //查看大图，暂无效
            handlePictureCardPreview(file) {
                this.dialogImageUrl = file.response;
                this.dialogVisible = true;
            },
            //商品介绍图片上传成功
            uploadSuccess(response){
                //拿到服务器响应的图片
                this.spuform.decript.push(response)
             //   console.log("删除之前的:"+this.spuform.decript);

            },
            //sku图片上传成功
            uploadBySkuImgSuccess(response,file,index){
                //拿到服务器响应的图片
               // alert(response);
              //  alert(file);
               // alert(index)

                this.spuform.skus[index].images.push(response)
                console.log("删除之前的:"+this.spuform.skus[0].images);

            },
            //第一个进度条的下一步（进到规格参数）
            submitFormOne(formName) {
       /*
       *
                console.log("第一个表格的参数"+this.spuform.spuName)
                console.log("第一个表格的参数"+this.spuform.spuDescription)
                console.log("第一个表格的参数"+this.spuform.catalog_id)
                console.log("第一个表格的参数"+this.spuform.weight)
                console.log("第一个表格的参数"+this.spuform.brand_id)
                console.log("第一个表格的参数"+this.spuform.date2)
                console.log("第一个表格的参数"+this.spuform.bounds.buyBounds+"::"+this.spuform.bounds.growBounds)
                console.log("第一个表格的参数"+this.spuform.decript)
       *
       * */



                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        //去查找当前分类下的全部分组信息
                        axios.get(glodate.serverZuul+"attrGroup/findAllAttrOrGroupByGroupIdAndCatelogId",{params:{
                                'catelogId':this.spuform.catalog_id
                            }}).then(response=>{
                            this.javaapi.tabGroupValue=response.data.data;

                        })
                        this.active=1;
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            },
            //第二个进度条的下一条（进到销售属性）
            //查询全部销售属性和值
            submitFormTwo(formName) {
                this.generateSaleAttrs();//执行将属性绑定到spuform里面
             //测试取数据
                let str=this.spuform.baseAttrs;
                console.log(str)
                //根据分类id查询全部销售属性和值
                axios.get(glodate.serverZuul+"pmsAttr/getSkuSaleValueByCatelogId",{params:{'catalog_id':this.spuform.catalog_id}})
                    .then(response=>{
                        this.javaapi.attrs_Sales=response.data.data;
                      //  console.log(response.data.data);
                    })

                this.active=2;

            },
            //第三个进度条的下一条（进到sku信息）
            skuData(){
                this.active=3;
                //根据笛卡尔积运算进行生成sku
                let checkvalues = [];
                this.attrs_Sales_Attrs=[];
                this.spuform.skus=[];//清空skus里面的内容，以防在最后一个页面点击上一步的时候重复数据
                this.javaapi.attrs_Sales.forEach(item => {
                    this.spuform.skus.attr=[];


                    // checkvalues.push(item);
                    if(item.attr_values!=null){

                        console.log("测试选中的销售属性"+item.attr_values);
                        //判断是否选中
                        //   console.log(item.attr_values);
                        if(item.attr_values.length>0){

                     //       console.log(item.attr_values);
                            var privatevalues=[];
                            let salevalues={
                                attr_id:item.attr_id,
                                attr_name: item.attr_name,
                                attr_values:[]
                            }
                            for(let i=0;i<item.attr_values.length;i++){

                                if(item.attr_values[i].checked==true){
                                    privatevalues.push(item.attr_values[i].values);
                                    salevalues.attr_values.push(item.attr_values[i].values);


                                }
                            }
                            //进行一次转换，来将选中的值才能存入到这个集合里面
                            if(salevalues.attr_values.length>0){
                               // console.log(salevalues);
                                this.attrs_Sales_Attrs.push(salevalues);
                                checkvalues.push(privatevalues);
                            }




                        }

                    }

                });

              //  console.log(checkvalues.length);
                  console.log(this.attrs_Sales_Attrs);
                //   console.log(this.attrs_Sales_Attrs);
             //   console.log("即将开始笛卡尔")
                let descartes=this.descartes(checkvalues);
               // console.log("生成的组合", JSON.stringify(descartes));
                //有多少descartes就有多少sku
                let skus = [];

              //生成sku组

                descartes.forEach((descar,descaridx)=>{


                    let attrArray=[];
                    descar.forEach((de,index)=>{

                        //构造saleattr信息
                        //alert(index)
                        let saleAttrItem={
                           attr_id:this.attrs_Sales_Attrs[index].attr_id,
                            attr_name:this.attrs_Sales_Attrs[index].attr_name,
                            attr_value:de
                        };
                        attrArray.push(saleAttrItem);
                     //   console.log("list::::"+this.attrs_Sales_Attrs[index].attr_id);
                     //   console.log("list::::"+this.attrs_Sales_Attrs[index].attr_name);
                      //  console.log("list::::"+de);
                    })
                    //绑定会员价
                    let memberPrices=[];
                     if(this.javaapi.memberLevels.length>0){
                         for(let i=0;i<this.javaapi.memberLevels.length;i++){
                             memberPrices.push({
                                id:this.javaapi.memberLevels[i].id,
                                name:this.javaapi.memberLevels[i].name,
                             price:0
                             })
                         }
                     }
                    let res = this.hasAndReturnSku(this.spuform.skus, descar);
                    if (res === null) {
                        skus.push({
                            attr: attrArray,
                            sku_name: this.spuform.spu_name + " " + descar.join(" "),
                            price: 0,
                            sku_title: this.spuform.spu_name + " " + descar.join(" "),
                            sku_subtitle: "",
                            images: [],
                            descar:descar,
                            fullCount: 0,
                            discount: 0,
                            countStatus: 0,
                            fullPrice: 0.0,
                            reducePrice: 0.0,
                            priceStatus: 0,
                            memberPrice: new Array().concat(memberPrices)
                        });
                    } else {
                        skus.push(res);
                    }
                })
                this.spuform.skus=skus;
               // console.log("结果!!!", this.spuform.skus.length+"测试！！！"+this.attrs_Sales_Attrs.length);
                for(let i=0;i<skus.length;i++){
                 console.log(skus[i].memberPrice+"--------------");
                }
              //  console.log("skus:"+attrArray)
            },
            //保存信息
            endaddspuform(formName){
                //最后一步保存信息,执行一个loading加载


               /*
               *  const loading = this.$loading({
                    lock: true,
                    text: '正在保存信息，请耐心等待',
                    spinner: 'el-icon-loading',
                    background: 'rgba(0, 0, 0, 0.7)'
                });
               * */

                //设置关闭的时间
                $.ajax({
                    type: 'post',
                    headers:{'Content-Type':'application/json;charset=utf8'},
                    dataType:"json",
                    url: glodate.serverZuul+"product/savespu",
                    data:JSON.stringify(this.spuform),
                    success:function (x){
                        if(x.code==200){
                            alert("保存成功");
                            console.log(this.spuform);
                            loading.close();
                        }else{
                            setTimeout(() => {
                                loading.close();
                            }, 3000);
                        }

                    }
                })


            },
            //判断如果包含之前的sku的descar组合，就返回这个sku的详细信息
            hasAndReturnSku(skus, descar) {
                let res = null;
                if (skus.length > 0) {
                    for (let i = 0; i < skus.length; i++) {
                        if (skus[i].descar.join(" ") == descar.join(" ")) {
                            res = skus[i];
                        }
                    }
                }
                return res;
            },
            //自定义的时候赋值
            handleInputConfirm(ids) {
                let inputValue = this.javaapi.attrs_Sales[ids].value;
               // console.log(inputValue);
                if (inputValue) {
                    alert("不为空")
                    if(this.javaapi.attrs_Sales[ids].attr_values==null){
                        this.javaapi.attrs_Sales[ids].attr_values=[]
                        this.javaapi.attrs_Sales[ids].attr_values.push({"values":inputValue,"checked":false})
                    }else{
                        if (!this.javaapi.attrs_Sales[ids].attr_values.includes(inputValue)) {
                            this.javaapi.attrs_Sales[ids].attr_values.push({"values":inputValue,"checked":false})
                        }
                    }
                    this.javaapi.attrs_Sales[ids].view = false;
                    this.javaapi.attrs_Sales[ids].value = '';

                }else{
                    this.javaapi.attrs_Sales[ids].view = false;
                    this.javaapi.attrs_Sales[ids].value = '';
                }

            },
            showInput(idx) {

               // console.log("``````", idx);
                this.javaapi.attrs_Sales[idx].view = true;
            },
            //将第二个页面的基础属性和值绑定到spu里面
            generateSaleAttrs(){
                this.spuform.baseAttrs=[];
                this.javaapi.tabGroupValue.forEach(item=>{
                    //console.log(item);
                    item.allAttrByGroupIdAndCatelogId.forEach(attr=>{

                        let {attr_id,attrValues,attr_name,showDesc}=attr;
                        //跳过没有录入值的属性
                        if(attrValues!=""){
                            if (attrValues instanceof Array) {
                                //多个值用;隔开
                                attrValues = attrValues.join(";");
                            }
                           // console.log("id:"+attrId);
                           // showDesc：先写死，这里是要转换下，因为后台的原因写的id不统一
                            this.spuform.baseAttrs.push({'attrId':attr_id,attrValues,'attrName':attr_name,'showDesc':1});
                        }
                    });

                });
            },
            //笛卡尔积运算
            //笛卡尔积运算
            descartes(list) {
                //parent上一级索引;count指针计数
                var point = {};

                var result = [];
                var pIndex = null;
                var tempCount = 0;
                var temp = [];

                //根据参数列生成指针对象
                for (var index in list) {
                    if (typeof list[index] == "object") {
                        point[index] = { parent: pIndex, count: 0 };
                        pIndex = index;
                    }
                }

                //单维度数据结构直接返回
                if (pIndex == null) {
                    return list;
                }

                //动态生成笛卡尔积
                while (true) {
                    for (var index in list) {
                        tempCount = point[index]["count"];
                        temp.push(list[index][tempCount]);
                    }

                    //压入结果数组
                    result.push(temp);
                    temp = [];

                    //检查指针最大值问题
                    while (true) {
                        if (point[index]["count"] + 1 >= list[index].length) {
                            point[index]["count"] = 0;
                            pIndex = point[index]["parent"];
                            if (pIndex == null) {
                                return result;
                            }

                            //赋值parent进行再次检查
                            index = pIndex;
                        } else {
                            point[index]["count"]++;
                            break;
                        }
                    }
                }
            },
            getMemberLevel(){
                //查询全部会员等级
                axios.get(glodate.serverZuul+"memberLevel/findAllLevel").then((x)=>{
                          this.javaapi.memberLevels=x.data.data;
                })

            }


        },
    })
</script>
</html>

